﻿using System;
using UnityEngine;

public class TimerVO
{
    public Action fun;
    public float delay;
    public float curTime;
    //添加时是否触发调用
    public bool isInit;

    /// <summary>
    /// 定时器
    /// </summary>
    public TimerVO(float delay, Action fun, bool isInit)
    {
        this.delay = delay;
        this.fun = fun;
        this.isInit = isInit;
    }

    public void Init()
    {
        if (isInit)
        {
            curTime = 0;
            Update();
        }
    }

    public void Update()
    {
        curTime += Time.deltaTime;
        if (curTime >= delay)
        {
            curTime = 0;
            fun();
        }
    }
}